Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Codecrew
/
Moya
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
30
Merge Requests
2
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit f2e1cd30
authored
Feb 17, 2018
by
Tuukka Kivilahti
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin' into nfcTagLogo
2 parents
48e39fee
341df336
Pipeline
#30
failed
in 0 seconds
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
12 additions
and
268 deletions
code/moya-parent/pom.xml
code/moya-restpojo/pom.xml
code/moya-web/src/main/java/fi/codecrew/moya/HostnameFilter.java
code/moya-web/src/main/java/fi/codecrew/moya/exceptions/BortalExceptionHandler.java
code/moya-web/src/main/java/fi/codecrew/moya/servlet/BortalCommand.java
code/moya-web/src/main/java/fi/codecrew/moya/servlet/BortalPasswordAuthenticator.java
code/pom.xml
code/moya-parent/pom.xml
View file @
f2e1cd3
...
...
@@ -24,7 +24,7 @@
<!-- Primefaces dependency -->
<groupId>
commons-fileupload
</groupId>
<artifactId>
commons-fileupload
</artifactId>
<version>
1.3.
2
</version>
<version>
1.3.
3
</version>
</dependency>
<dependency>
<groupId>
org.primefaces.extensions
</groupId>
...
...
@@ -38,11 +38,6 @@
<version>
2.1
</version>
</dependency>
<dependency>
<groupId>
org.apache.sshd
</groupId>
<artifactId>
sshd-core
</artifactId>
<version>
0.14.0
</version>
</dependency>
<dependency>
<!-- Java melody dependency -->
<groupId>
org.jrobin
</groupId>
<artifactId>
jrobin
</artifactId>
...
...
@@ -61,7 +56,7 @@
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpclient
</artifactId>
<version>
4.5.
3
</version>
<version>
4.5.
5
</version>
</dependency>
<dependency>
<groupId>
org.testng
</groupId>
...
...
@@ -112,7 +107,7 @@
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-lang3
</artifactId>
<version>
3.
5
</version>
<version>
3.
7
</version>
</dependency>
<dependency>
<groupId>
javax.json
</groupId>
...
...
code/moya-restpojo/pom.xml
View file @
f2e1cd3
...
...
@@ -25,6 +25,7 @@
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-source-plugin
</artifactId>
<version>
3.0.1
</version>
<executions>
<execution>
<id>
attach-sources
</id>
...
...
code/moya-web/src/main/java/fi/codecrew/moya/HostnameFilter.java
View file @
f2e1cd3
...
...
@@ -196,7 +196,10 @@ public class HostnameFilter implements Filter {
}
}
if
(
httpRequest
.
getUserPrincipal
()
==
null
)
{
// If we are still unlogged, ie we are a normal user
if
(
httpRequest
.
getUserPrincipal
()
==
null
)
{
// Verify that we have an open session.
httpRequest
.
getSession
(
true
);
try
{
authtype
=
AuthType
.
ANON
;
httpRequest
.
login
(
User
.
ANONYMOUS_LOGINNAME
+
'@'
+
hostname
,
null
);
...
...
code/moya-web/src/main/java/fi/codecrew/moya/exceptions/BortalExceptionHandler.java
View file @
f2e1cd3
...
...
@@ -61,9 +61,10 @@ public class BortalExceptionHandler extends ExceptionHandlerWrapper {
logger
.
debug
(
"Found exception! handing it: {}"
,
t
.
getClass
().
toString
());
if
(
t
instanceof
ViewExpiredException
)
{
logger
.
debug
(
"ViewExpiredException details"
,
t
);
errorpage
(
i
,
t
,
"/viewExpired"
);
}
Throwable
cause
=
t
.
getCause
();
for
(
int
loop
=
0
;
loop
<
20
&&
cause
!=
null
;
++
loop
)
{
logger
.
debug
(
"Cause not null, but {}: {}, checking"
+
cause
.
getClass
(),
cause
.
getMessage
());
...
...
code/moya-web/src/main/java/fi/codecrew/moya/servlet/BortalCommand.java
deleted
100644 → 0
View file @
48e39fe
/*
* Copyright Codecrew Ry
*
* All rights reserved.
*
* This license applies to any software containing a notice placed by the
* copyright holder. Such software is herein referred to as the Software.
* This license covers modification, distribution and use of the Software.
*
* Any distribution and use in source and binary forms, with or without
* modification is not permitted without explicit written permission from the
* copyright owner.
*
* A non-exclusive royalty-free right is granted to the copyright owner of the
* Software to use, modify and distribute all modifications to the Software in
* future versions of the Software.
*
*/
package
fi
.
codecrew
.
moya
.
servlet
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.io.OutputStream
;
import
java.io.OutputStreamWriter
;
import
java.nio.charset.Charset
;
import
java.util.HashMap
;
import
org.apache.sshd.server.Command
;
import
org.apache.sshd.server.Environment
;
import
org.apache.sshd.server.ExitCallback
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
fi.codecrew.moya.clientutils.BortalLocalContextHolder
;
import
fi.codecrew.moya.cmdline.ICommandlineCommand
;
public
class
BortalCommand
implements
Command
,
Runnable
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
BortalCommand
.
class
);
private
OutputStreamWriter
errstream
;
private
ExitCallback
exitCallback
;
private
InputStreamReader
instream
;
private
OutputStreamWriter
outstream
;
private
BortalLocalContextHolder
contextHolder
;
private
Charset
UTF8
=
Charset
.
forName
(
"UTF-8"
);
private
HashMap
<
String
,
ICommandlineCommand
>
commandMap
=
new
HashMap
<
String
,
ICommandlineCommand
>();
public
BortalCommand
(
BortalLocalContextHolder
context
)
{
contextHolder
=
context
;
}
public
BortalCommand
addCommandlineCommand
(
String
name
,
ICommandlineCommand
c
)
{
this
.
commandMap
.
put
(
name
,
c
);
return
this
;
}
@Override
public
void
setInputStream
(
InputStream
in
)
{
instream
=
new
InputStreamReader
(
in
,
UTF8
);
}
@Override
public
void
setOutputStream
(
OutputStream
out
)
{
outstream
=
new
OutputStreamWriter
(
out
,
UTF8
);
}
@Override
public
void
setErrorStream
(
OutputStream
err
)
{
errstream
=
new
OutputStreamWriter
(
err
,
UTF8
);
}
@Override
public
void
setExitCallback
(
ExitCallback
callback
)
{
exitCallback
=
callback
;
}
@Override
public
void
start
(
Environment
env
)
throws
IOException
{
logger
.
info
(
"Starting something..."
);
new
Thread
(
this
).
start
();
}
@Override
public
void
destroy
()
{
logger
.
info
(
"destroying ssh command"
);
}
@Override
public
void
run
()
{
BortalLocalContextHolder
.
copy
(
contextHolder
);
try
{
logger
.
info
(
"Created new bortalCommane"
);
outstream
.
write
(
"Hello you..."
);
StringBuilder
cmdBuilder
=
new
StringBuilder
();
// prime 0 return value
int
returnValue
=
0
;
while
(
true
)
{
if
(!
instream
.
ready
())
{
Thread
.
sleep
(
100
);
}
else
{
char
inchar
=
(
char
)
instream
.
read
();
if
(
inchar
==
'\n'
||
inchar
==
'\r'
)
{
outstream
.
write
(
"\r\n"
);
outstream
.
flush
();
returnValue
=
parseCommand
(
cmdBuilder
.
toString
());
//outstream.write("[" + returnValue + "] " + BortalLocalContextHolder.getInstance().getLoginContext().getSubject().getPrincipals().iterator().next().getName() + " # ");
outstream
.
flush
();
cmdBuilder
=
new
StringBuilder
();
}
else
{
outstream
.
write
(
inchar
);
outstream
.
flush
();
cmdBuilder
.
append
(
inchar
);
}
}
}
}
catch
(
InterruptedException
e
)
{
logger
.
warn
(
"Running command interrupted"
,
e
);
}
catch
(
IOException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
exitCallback
.
onExit
(
3
);
}
private
int
parseCommand
(
String
args
)
{
String
[]
argv
=
null
;
if
(
args
!=
null
)
{
if
(
args
.
length
()
==
0
)
return
0
;
argv
=
args
.
split
(
" "
);
}
if
(
argv
!=
null
&&
argv
.
length
>
0
)
{
logger
.
info
(
"received command {}"
,
argv
[
0
]);
ICommandlineCommand
cmd
;
if
((
cmd
=
this
.
commandMap
.
get
(
argv
[
0
]))
!=
null
)
{
return
cmd
.
execute
(
argv
,
this
.
instream
,
this
.
outstream
,
this
.
errstream
);
}
else
{
try
{
this
.
errstream
.
write
(
"unknown command\r\n"
);
this
.
errstream
.
flush
();
}
catch
(
IOException
ioe
)
{}
return
-
1
;
}
}
else
{
return
0
;
}
}
}
code/moya-web/src/main/java/fi/codecrew/moya/servlet/BortalPasswordAuthenticator.java
deleted
100644 → 0
View file @
48e39fe
/*
* Copyright Codecrew Ry
*
* All rights reserved.
*
* This license applies to any software containing a notice placed by the
* copyright holder. Such software is herein referred to as the Software.
* This license covers modification, distribution and use of the Software.
*
* Any distribution and use in source and binary forms, with or without
* modification is not permitted without explicit written permission from the
* copyright owner.
*
* A non-exclusive royalty-free right is granted to the copyright owner of the
* Software to use, modify and distribute all modifications to the Software in
* future versions of the Software.
*
*/
package
fi
.
codecrew
.
moya
.
servlet
;
import
java.io.IOException
;
import
java.security.Principal
;
import
java.util.HashSet
;
import
javax.resource.spi.security.PasswordCredential
;
import
javax.security.auth.Subject
;
import
javax.security.auth.callback.Callback
;
import
javax.security.auth.callback.CallbackHandler
;
import
javax.security.auth.callback.NameCallback
;
import
javax.security.auth.callback.PasswordCallback
;
import
javax.security.auth.callback.UnsupportedCallbackException
;
import
javax.security.auth.login.LoginContext
;
import
org.apache.sshd.server.PasswordAuthenticator
;
import
org.apache.sshd.server.session.ServerSession
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
fi.codecrew.moya.clientutils.BortalLocalContextHolder
;
// Deprecated: TODO: Pitäisi käydä ajatuksella läpi!
@Deprecated
()
public
class
BortalPasswordAuthenticator
implements
PasswordAuthenticator
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
BortalPasswordAuthenticator
.
class
);
private
BortalLocalContextHolder
context
;
public
BortalPasswordAuthenticator
(
BortalLocalContextHolder
instance
)
{
super
();
context
=
instance
;
}
@Override
public
boolean
authenticate
(
String
username
,
String
password
,
ServerSession
session
)
{
BortalLocalContextHolder
.
copy
(
context
);
return
authenticate
(
username
,
password
);
}
public
boolean
authenticate
(
final
String
username
,
final
String
password
)
{
try
{
PasswordCredential
pwdcred
=
new
PasswordCredential
(
username
,
password
.
toCharArray
());
HashSet
<
PasswordCredential
>
privcred
=
new
HashSet
<
PasswordCredential
>();
privcred
.
add
(
pwdcred
);
Subject
subject
=
new
Subject
(
false
,
new
HashSet
<
Principal
>(),
new
HashSet
<
Object
>(),
privcred
);
LoginContext
loginContext
=
new
LoginContext
(
"bortalRealm"
,
subject
,
new
CallbackHandler
()
{
public
void
handle
(
Callback
[]
callbacks
)
throws
IOException
,
UnsupportedCallbackException
{
for
(
int
i
=
0
;
i
<
callbacks
.
length
;
i
++)
{
Callback
cb
=
callbacks
[
i
];
logger
.
info
(
"Handling callback. {}"
,
cb
);
if
(
cb
instanceof
NameCallback
)
{
logger
.
info
(
"Handling name callback"
);
((
NameCallback
)
callbacks
[
i
]).
setName
(
username
);
}
else
if
(
cb
instanceof
PasswordCallback
)
{
logger
.
info
(
"Handling password callback"
);
((
PasswordCallback
)
cb
).
setPassword
(
password
.
toCharArray
());
}
else
{
throw
new
UnsupportedCallbackException
(
cb
);
}
}
}
});
loginContext
.
login
();
// loginContext.logout();
return
true
;
}
catch
(
Exception
e
)
{
logger
.
error
(
"Authentication failed with error"
,
e
);
return
false
;
}
}
}
code/pom.xml
View file @
f2e1cd3
...
...
@@ -31,10 +31,10 @@
<swagger.version>
1.5.13
</swagger.version>
<slf4j.version>
1.7.25
</slf4j.version>
<logback.version>
1.2.3
</logback.version>
<testng.version>
6.1
1
</testng.version>
<testng.version>
6.1
4.2
</testng.version>
<findbugs.version>
3.0.1
</findbugs.version>
<findbugs-maven.version>
3.0.5
</findbugs-maven.version>
<javamelody.version>
1.
65
.0
</javamelody.version>
<javamelody.version>
1.
70
.0
</javamelody.version>
<primefaces.version>
6.0
</primefaces.version>
<primefaces.themeversion>
1.0.10
</primefaces.themeversion>
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment