Skip to content

Commit 5372698

Browse files
committed
add samples from apache shiro
1 parent 8b13b1a commit 5372698

File tree

100 files changed

+6900
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+6900
-0
lines changed

aspectj/pom.xml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one
4+
~ or more contributor license agreements. See the NOTICE file
5+
~ distributed with this work for additional information
6+
~ regarding copyright ownership. The ASF licenses this file
7+
~ to you under the Apache License, Version 2.0 (the
8+
~ "License"); you may not use this file except in compliance
9+
~ with the License. You may obtain a copy of the License at
10+
~
11+
~ http://www.apache.org/licenses/LICENSE-2.0
12+
~
13+
~ Unless required by applicable law or agreed to in writing,
14+
~ software distributed under the License is distributed on an
15+
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
~ KIND, either express or implied. See the License for the
17+
~ specific language governing permissions and limitations
18+
~ under the License.
19+
-->
20+
<!--suppress osmorcNonOsgiMavenDependency -->
21+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
22+
23+
<parent>
24+
<groupId>org.apache.shiro.samples</groupId>
25+
<artifactId>shiro-samples</artifactId>
26+
<version>1.2.4-SNAPSHOT</version>
27+
<relativePath>../pom.xml</relativePath>
28+
</parent>
29+
30+
<modelVersion>4.0.0</modelVersion>
31+
<artifactId>samples-aspectj</artifactId>
32+
<name>Apache Shiro :: Samples :: AspectJ</name>
33+
34+
<build>
35+
<plugins>
36+
<plugin>
37+
<groupId>org.codehaus.mojo</groupId>
38+
<artifactId>aspectj-maven-plugin</artifactId>
39+
<version>1.4</version>
40+
<configuration>
41+
<source>1.5</source>
42+
<target>1.5</target>
43+
<showWeaveInfo>true</showWeaveInfo>
44+
<aspectLibraries>
45+
<aspectLibrary>
46+
<groupId>org.apache.shiro</groupId>
47+
<artifactId>shiro-aspectj</artifactId>
48+
</aspectLibrary>
49+
</aspectLibraries>
50+
</configuration>
51+
<executions>
52+
<execution>
53+
<id>aspectj-compile</id>
54+
<goals>
55+
<goal>compile</goal>
56+
<goal>test-compile</goal>
57+
</goals>
58+
</execution>
59+
</executions>
60+
</plugin>
61+
</plugins>
62+
</build>
63+
64+
<dependencies>
65+
<dependency>
66+
<groupId>org.apache.shiro</groupId>
67+
<artifactId>shiro-aspectj</artifactId>
68+
</dependency>
69+
<dependency>
70+
<groupId>commons-lang</groupId>
71+
<artifactId>commons-lang</artifactId>
72+
<version>2.4</version>
73+
</dependency>
74+
<dependency>
75+
<groupId>log4j</groupId>
76+
<artifactId>log4j</artifactId>
77+
<scope>runtime</scope>
78+
</dependency>
79+
<dependency>
80+
<groupId>org.slf4j</groupId>
81+
<artifactId>slf4j-log4j12</artifactId>
82+
<scope>runtime</scope>
83+
</dependency>
84+
</dependencies>
85+
86+
</project>
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.shiro.samples.aspectj.bank;
20+
21+
22+
import org.apache.commons.lang.builder.ToStringBuilder;
23+
import org.apache.commons.lang.builder.ToStringStyle;
24+
25+
import java.sql.Timestamp;
26+
import java.util.ArrayList;
27+
import java.util.Date;
28+
import java.util.List;
29+
30+
public class Account {
31+
32+
private static long _SEQUENCE;
33+
34+
private long _id;
35+
36+
private String _ownerName;
37+
38+
private volatile boolean _isActive;
39+
40+
private double _balance;
41+
42+
private final List<AccountTransaction> _transactions;
43+
44+
private String _createdBy;
45+
46+
private Date _creationDate;
47+
48+
public Account(String anOwnerName) {
49+
_id = ++_SEQUENCE;
50+
_ownerName = anOwnerName;
51+
_isActive = true;
52+
_balance = 0.0d;
53+
_transactions = new ArrayList<AccountTransaction>();
54+
_createdBy = "unknown";
55+
_creationDate = new Date();
56+
}
57+
58+
/**
59+
* Returns the id attribute.
60+
*
61+
* @return The id value.
62+
*/
63+
public long getId() {
64+
return _id;
65+
}
66+
67+
/**
68+
* Returns the ownerName attribute.
69+
*
70+
* @return The ownerName value.
71+
*/
72+
public String getOwnerName() {
73+
return _ownerName;
74+
}
75+
76+
/**
77+
* Returns the isActive attribute.
78+
*
79+
* @return The isActive value.
80+
*/
81+
public boolean isActive() {
82+
return _isActive;
83+
}
84+
85+
/**
86+
* Changes the value of the attributes isActive.
87+
*
88+
* @param aIsActive The new value of the isActive attribute.
89+
*/
90+
public void setActive(boolean aIsActive) {
91+
_isActive = aIsActive;
92+
}
93+
94+
/**
95+
* Changes the value of the attributes ownerName.
96+
*
97+
* @param aOwnerName The new value of the ownerName attribute.
98+
*/
99+
public void setOwnerName(String aOwnerName) {
100+
_ownerName = aOwnerName;
101+
}
102+
103+
/**
104+
* Returns the balance attribute.
105+
*
106+
* @return The balance value.
107+
*/
108+
public double getBalance() {
109+
return _balance;
110+
}
111+
112+
/**
113+
* Returns the transactions attribute.
114+
*
115+
* @return The transactions value.
116+
*/
117+
public List<AccountTransaction> getTransactions() {
118+
return _transactions;
119+
}
120+
121+
protected void applyTransaction(AccountTransaction aTransaction) throws NotEnoughFundsException, InactiveAccountException {
122+
if (!_isActive) {
123+
throw new InactiveAccountException("Unable to apply " + aTransaction.getType() + " of amount " + aTransaction.getAmount() + " to account " + _id);
124+
}
125+
126+
synchronized (_transactions) {
127+
if (AccountTransaction.TransactionType.DEPOSIT == aTransaction.getType()) {
128+
_transactions.add(aTransaction);
129+
_balance += aTransaction.getAmount();
130+
131+
} else if (AccountTransaction.TransactionType.WITHDRAWAL == aTransaction.getType()) {
132+
if (_balance < aTransaction.getAmount()) {
133+
throw new NotEnoughFundsException("Unable to withdraw " + aTransaction.getAmount() + "$ from account " + _id + " - current balance is " + _balance);
134+
}
135+
_transactions.add(aTransaction);
136+
_balance -= aTransaction.getAmount();
137+
138+
} else {
139+
throw new IllegalArgumentException("The transaction passed in has an invalid type: " + aTransaction.getType());
140+
}
141+
}
142+
}
143+
144+
/**
145+
* Changes the value of the attributes createdBy.
146+
*
147+
* @param aCreatedBy The new value of the createdBy attribute.
148+
*/
149+
protected void setCreatedBy(String aCreatedBy) {
150+
_createdBy = aCreatedBy;
151+
}
152+
153+
/**
154+
* Returns the createdBy attribute.
155+
*
156+
* @return The createdBy value.
157+
*/
158+
public String getCreatedBy() {
159+
return _createdBy;
160+
}
161+
162+
/**
163+
* Returns the creationDate attribute.
164+
*
165+
* @return The creationDate value.
166+
*/
167+
public Date getCreationDate() {
168+
return _creationDate;
169+
}
170+
171+
/* (non-Javadoc)
172+
* @see java.lang.Object#toString()
173+
*/
174+
175+
public String toString() {
176+
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).
177+
append("id", _id).
178+
append("ownerName", _ownerName).
179+
append("isActive", _isActive).
180+
append("balance", _balance).
181+
append("tx.count", _transactions.size()).
182+
append("createdBy", _createdBy).
183+
append("creationDate", new Timestamp(_creationDate.getTime())).
184+
toString();
185+
}
186+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.shiro.samples.aspectj.bank;
20+
21+
public class AccountNotFoundException extends BankServiceException {
22+
23+
public AccountNotFoundException(String aMessage) {
24+
super(aMessage);
25+
}
26+
27+
}

0 commit comments

Comments
 (0)